﻿using Anke.SHManage.IDAL;
using Anke.SHManage.Model;
using Anke.SHManage.MSSQLDAL;
using Anke.SHManage.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Anke.SHManage.BLL
{
    public class MobileTaskBLL
    {
        MobileTaskDAL idal = new MobileTaskDAL();

        //IMobileTaskDAL idal = DataAccess.GetMobileTaskDAL();
        public List<MobileTaskInfo> GetMobileTaskListBy(string userCode, string taskCode, ref string errorMsg)
        {
            return idal.GetMobileTaskListBy(userCode, taskCode, ref errorMsg);
        }

        /// <summary>
        /// 20151109增加为PAD，根据版本号和标识查询
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="version"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public List<I_Material> GetMainDictionary(string tableName, string version, string state)
        {
            return idal.GetMainDictionary(tableName, version, state);
        }

        ///// <summary>
        ///// 20151210增加PAD保存收费
        ///// </summary>
        ///// <param name="info"></param>
        ///// <param name="patientChargeLogInfo"></param>
        ///// <param name="errorMsg"></param>
        ///// <returns></returns>
        //public bool MobileSavePatientCharge(M_PatientCharge info, M_PatientChargeLog patientChargeLogInfo, ref string errorMsg)
        //{
        //    //2018-12-11 zch 
        //    if (info != null && info.InvoiceNumber != null)
        //    {
        //        new I_InvoiceApprovalBLL().DealUsedInvoiceRecord(info.InvoiceNumber);
        //    }

        //    return idal.MobileSavePatientCharge(info, patientChargeLogInfo, ref errorMsg);
        //}

        /// <summary>
        /// 20151210增加PAD保存收费
        /// 2021-10-18 plq 医保上线移植
        /// </summary>
        /// <param name="info"></param>
        /// <param name="patientChargeLogInfo"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public bool MobileSavePatientCharge(string TaskCode, int PatientOrder, M_PatientCharge info, M_PatientChargeLog patientChargeLogInfo, List<M_PatientChargeDetail> patientChargeDetailInfo, List<M_PatientChargeDetailLog> patientChargeDetailLogInfo, bool Isvalid, ref string errorMsg)
        {
            //2018-12-11 zch 
            if (info != null && info.InvoiceNumber != null)
            {
                new I_InvoiceApprovalBLL().DealUsedInvoiceRecord(info.InvoiceNumber);
            }
            //return idal.MobileSavePatientCharge(info, patientChargeLogInfo, ref errorMsg);
            return idal.MobileSavePatientCharge(TaskCode, PatientOrder, info, patientChargeLogInfo, patientChargeDetailInfo, patientChargeDetailLogInfo, Isvalid, ref errorMsg);

        }

        //20151210增加PAD根据任务编码序号查询收费主表信息
        public void GetPatientChargeInfo(string taskCode, int patientOrder, out M_PatientCharge info)
        {
            idal.GetPatientChargeInfo(taskCode, patientOrder, out info);
        }

        //20151211增加PAD新增病历信息
        public bool InsertPAD(object info, M_PatientRecordAppend pra
            , M_PatientRecordCPR prCPR, List<M_PatientRecordDiag> prDiag
            , List<M_PatientRecordECGImpressions> prECG
            , List<M_PatientRecordRescue> prRescue, List<M_PatientRecordMeasure> prMeasure
            , List<M_PatientRecordDrug> prDrug, List<M_PatientRecordSanitation> prSanitation
            , List<M_PatientRecordLossDrug> prLossDrug, List<M_PatientRecordLossSanitation> prLossSanitation)
        {
            return idal.InsertPAD(info, pra, prCPR, prDiag, prECG, prRescue
                , prMeasure, prDrug, prSanitation, prLossDrug, prLossSanitation);
        }

        //20151211增加PAD修改病历信息
        public bool UpdatePAD(object info, M_PatientRecordAppend pra
            , M_PatientRecordCPR prCPR, List<M_PatientRecordDiag> prDiag
            , List<M_PatientRecordECGImpressions> prECG
            , List<M_PatientRecordRescue> prRescue, List<M_PatientRecordMeasure> prMeasure
            , List<M_PatientRecordDrug> prDrug, List<M_PatientRecordSanitation> prSanitation
            , List<M_PatientRecordLossDrug> prLossDrug, List<M_PatientRecordLossSanitation> prLossSanitation)
        {
            return idal.UpdatePAD(info, pra, prCPR, prDiag, prECG, prRescue
                , prMeasure, prDrug, prSanitation, prLossDrug, prLossSanitation);
        }

        //根据工号获取中心编码
        public void GetCenterCode(string workCode, out string centerCode)
        {
            idal.GetCenterCode(workCode, out centerCode);
        }

        public List<MobileTaskInfo> GetMobileTaskListsBy(string begintime, string endtime, string centerCode, string taskOrder, ref string errorMsg)
        {
            return idal.GetMobileTaskListsBy(begintime, endtime, centerCode, taskOrder, ref errorMsg);
        }

        //20160421更新发票号
        public bool UpdateFaPiaoNumber(string TaskCode, int PatientOrder, string FaPiaoNumber)
        {
            return idal.UpdateFaPiaoNumber(TaskCode, PatientOrder, FaPiaoNumber);

        }

        ////2016-12-22 zch 单任务对多病历方式 业务逻辑
        //public List<MobileTaskInfo> getMobileTaskList(string userCode, string taskCode, ref string errorMsg)
        //{
        //    //根据userCode 先取任务表中前10条的任务信息.
        //    List<MobileTaskInfo> listTask = idal.GetMobileTaskListPOCO(userCode, taskCode, ref errorMsg);

        //    //再根据任务编码去遍历病历表中的信息. 
        //    foreach (MobileTaskInfo infoTask in listTask)
        //    {
        //        if (idal.getMobilePRSubmit(infoTask.RenWuBianMa))
        //        {
        //            listTask.Remove(infoTask); //将已提交的剔除掉
        //        }
        //    }
        //    //如果有一条未提交的就保留,全提交的就舍弃, 使用一个bool值来判断.



        // }




    }
}
